package com.binest.myLikes.service.impl;

import java.util.List;

import com.binest.common.core.domain.entity.SysUser;
import com.binest.common.core.domain.model.LoginUser;
import com.binest.common.utils.DateUtils;
import com.binest.common.utils.uuid.IdUtils;
import com.binest.figureInclusionMain.service.IFigureInclusionMainService;
import com.binest.hackathonInclusionMain.service.IHackathonInclusionMainService;
import com.binest.investorInclusionMain.service.IInvestorInclusionMainService;
import com.binest.kolInclusionMain.service.IKolInclusionMainService;
import com.binest.meetingInclusionMain.service.IMeetingInclusionMainService;
import com.binest.projectInclusionMain.service.IProjectInclusionMainService;
import com.binest.toolInclusionMain.service.IToolInclusionMainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.binest.myLikes.mapper.MyLikesMapper;
import com.binest.myLikes.domain.MyLikes;
import com.binest.myLikes.service.IMyLikesService;

import static com.binest.common.utils.SecurityUtils.getLoginUser;

/**
 * 我的点赞Service业务层处理
 * 
 * @author wwd
 * @date 2024-01-30
 */
@Service
public class MyLikesServiceImpl implements IMyLikesService 
{
    @Autowired
    private MyLikesMapper myLikesMapper;
    @Autowired
    private IProjectInclusionMainService projectInclusionMainService;

    @Autowired
    private IFigureInclusionMainService figureInclusionMainService;

    @Autowired
    private IHackathonInclusionMainService hackathonInclusionMainService;

    @Autowired
    private IInvestorInclusionMainService investorInclusionMainService;

    @Autowired
    private IMeetingInclusionMainService meetingInclusionMainService;


    @Autowired
    private IKolInclusionMainService kolInclusionMainService;

    @Autowired
    private IToolInclusionMainService toolInclusionMainService;

    /**
     * 查询我的点赞
     * 
     * @param id 我的点赞主键
     * @return 我的点赞
     */
    @Override
    public MyLikes selectMyLikesById(String id)
    {
        return myLikesMapper.selectMyLikesById(id);
    }

    /**
     * 查询我的点赞列表
     * 
     * @param myLikes 我的点赞
     * @return 我的点赞
     */
    @Override
    public List<MyLikes> selectMyLikesList(MyLikes myLikes)
    {
        return myLikesMapper.selectMyLikesList(myLikes);
    }

    /**
     * 新增我的点赞
     * 
     * @param myLikes 我的点赞
     * @return 结果
     */
    @Override
    public int insertMyLikes(MyLikes myLikes)
    {
        //获取当前登录用户
        LoginUser loginUser = getLoginUser();
        SysUser currentUser = loginUser.getUser();

        myLikes.setCreateTime(DateUtils.getNowDate());
        myLikes.setId(IdUtils.simpleUUID());
        myLikes.setCreateBy(currentUser.getUserId().toString());
        //判断收录类型 点赞
        if(myLikes.getInclusionType().equals("0")){
            //项目
            if(myLikes.getLikeType().equals("0")){
                projectInclusionMainService.addLikeCount(myLikes.getInclusionMainId());
            }else {
                projectInclusionMainService.reduceLikeCount(myLikes.getInclusionMainId());
            }

        } else if(myLikes.getInclusionType().equals("1")){
            //投资机构
            if(myLikes.getLikeType().equals("0")){
                investorInclusionMainService.addLikeCount(myLikes.getInclusionMainId());
            }else {
                investorInclusionMainService.reduceLikeCount(myLikes.getInclusionMainId());
            }


       } else if(myLikes.getInclusionType().equals("2")){
            //人物
            if(myLikes.getLikeType().equals("0")){
                figureInclusionMainService.addLikeCount(myLikes.getInclusionMainId());
            }else {
                figureInclusionMainService.reduceLikeCount(myLikes.getInclusionMainId());
            }

        } else if(myLikes.getInclusionType().equals("3")){
            //会议
            if(myLikes.getLikeType().equals("0")){
                meetingInclusionMainService.addLikeCount(myLikes.getInclusionMainId());
            }else {
                meetingInclusionMainService.reduceLikeCount(myLikes.getInclusionMainId());
            }

        } else if(myLikes.getInclusionType().equals("4")){
            //kol
            if(myLikes.getLikeType().equals("0")){
                kolInclusionMainService.addLikeCount(myLikes.getInclusionMainId());
            }else {
                kolInclusionMainService.reduceLikeCount(myLikes.getInclusionMainId());
            }

        } else if(myLikes.getInclusionType().equals("6")){
            //工具
            if(myLikes.getLikeType().equals("0")){
                toolInclusionMainService.addLikeCount(myLikes.getInclusionMainId());
            }else {
                toolInclusionMainService.reduceLikeCount(myLikes.getInclusionMainId());
            }
        } else if(myLikes.getInclusionType().equals("7")){
            //马拉松
            if(myLikes.getLikeType().equals("0")){
                hackathonInclusionMainService.addLikeCount(myLikes.getInclusionMainId());
            }else {
                hackathonInclusionMainService.reduceLikeCount(myLikes.getInclusionMainId());
            }

        }

        return myLikesMapper.insertMyLikes(myLikes);
    }

    /**
     * 修改我的点赞
     * 
     * @param myLikes 我的点赞
     * @return 结果
     */
    @Override
    public int updateMyLikes(MyLikes myLikes)
    {
        myLikes.setUpdateTime(DateUtils.getNowDate());
        return myLikesMapper.updateMyLikes(myLikes);
    }

    /**
     * 批量删除我的点赞
     * 
     * @param ids 需要删除的我的点赞主键
     * @return 结果
     */
    @Override
    public int deleteMyLikesByIds(String[] ids)
    {
        return myLikesMapper.deleteMyLikesByIds(ids);
    }

    /**
     * 删除我的点赞信息
     * 
     * @param id 我的点赞主键
     * @return 结果
     */
    @Override
    public int deleteMyLikesById(String id)
    {
        return myLikesMapper.deleteMyLikesById(id);
    }
}
